package nz.ac.massey.cs.compile;

import java.util.ArrayList;

import nz.ac.massey.cs.domain.Cell;

public class SumNumConstraint extends AbstractConstraint {

	@Override
	public boolean isViolated() {
		try
		{
			ArrayList<Cell> list = this.getCells();
			int sum = Integer.parseInt(getConstraintInfo("sum"));
			int currentSum =0;
			for(Cell c:list)
			{
				currentSum += Integer.parseInt(c.getValue());
			}
			if(currentSum > sum)
			{
				return false;
			}
		} catch (Exception e)
		{
			return true;
		}
		return false;
	}
	
	@Override
	public boolean isSatisfied()
	{
		try
		{
			ArrayList<Cell> list = this.getCells();
			int sum = Integer.parseInt(getConstraintInfo("sum"));
			int currentSum =0;
			for(Cell c:list)
			{
				currentSum += Integer.parseInt(c.getValue());
			}
			if(currentSum != sum)
			{
				return false;
			}
		} catch (Exception e)
		{
			return false;
		}
		return true;
	}

	@Override
	public void applyConstraintInfo(String constraintInfo) {
		// TODO Auto-generated method stub
		
	}

}
